﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Silvermoon.Controls.Forms;

namespace Silvermoon.WinControls
{
    public enum ExitMode
    {
        /// <summary>
        /// Only minimizes the hosting window.
        /// </summary>
        Minimize,

        /// <summary>
        /// Exits the application.
        /// </summary>
        Exit
    }

    public sealed class SMApplication
    {
        /// <summary>
        /// Begins running a standard application message loop on the current thread,
        ///  and makes the specified Silvermoon window visible.    
        /// <typeparam name="T">Type of window to show.</typeparam>
        /// <param name="title">Title of the application which appears in task manager.</param>
        /// <param name="exitMode">Specifies  how the application exits.</param>
        public static void Run<T>(string title, ExitMode exitMode) where T : Silvermoon.Controls.Window
        {
            HostForm form = new HostForm();
            form.Text = title;
            form.MinimizeBox = exitMode == ExitMode.Minimize;
            form.CreateWindow += () => Activator.CreateInstance<T>() as Silvermoon.Controls.Window;
            Application.Run(form);
        }

        /// <summary>
        /// Begins running a standard application message loop on the current thread,
        ///  and makes the specified Silvermoon window visible.    
        /// <typeparam name="T">Type of window to show.</typeparam>
        /// <param name="title">Title of the application which appears in task manager.</param>
        public static void Run<T>(string title) where T : Silvermoon.Controls.Window
        {
            Run<T>(title, ExitMode.Exit);
        }


    }
}
